//
//  BCWaitingShopVC.m
//  BangcaiBuy
//
//  Created by lsy on 16/7/6.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCWaitingShopVC.h"
#import "BCCircleView.h"
#import "BCPaidListingViewController.h"

@interface BCWaitingShopVC (){
    UIButton *goCheckBut;
    UIView *sliderBack;
    UIImageView *sliderImg;
    UILabel *timeLab;
    NSTimer *time;
    UILabel *timeLabel;
    
    UILabel *timeTitle;
    UILabel *shopAmount;
    UILabel *shop;
    NSInteger second;
    
    UIImageView *logoImg;
}
;@property(nonatomic, strong)BCCircleView *circle;


@end

@implementation BCWaitingShopVC


- (void)viewWillAppear:(BOOL)animated
{
    self.title = @"竞价中";
    self.view.backgroundColor = [UIColor whiteColor];
    [[BCShopCarManager sharedInstance] hideShopWindow];
    if (!self.rdv_tabBarController.tabBarHidden) {
        [self.rdv_tabBarController setTabBarHidden:YES];
    }
    
}

- (void)getView
{
    sliderBack = [[UIView alloc] init];
    sliderBack.backgroundColor = [UIColor colorWithRed:0.748  green:0.906  blue:0.907 alpha:1];
    sliderImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"进度条"]];
    second = 180;
    timeLab = [[UILabel alloc] init];
    timeLab.font = [UIFont systemFontOfSize:40];
    timeLab.textColor = [UIColor colorWithRed:0  green:0.744  blue:0.321 alpha:1];
    timeLab.text = [NSString stringWithFormat:@"%ld s", second];
    timeTitle = [[UILabel alloc] init];
    timeTitle.text = @"竞价中";
    timeTitle.textColor = [UIColor colorWithRed:0.510  green:0.510  blue:0.510 alpha:1];
    timeTitle.font = [UIFont systemFontOfSize:14];
    goCheckBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [goCheckBut setTitle:@"立即查看报价" forState:UIControlStateNormal];
    goCheckBut.layer.cornerRadius = 2;
    goCheckBut.titleLabel.font = [UIFont systemFontOfSize:14];
    goCheckBut.backgroundColor = [UIColor colorWithRed:0.061  green:0.747  blue:0.338 alpha:1];
    [goCheckBut setTintColor:[UIColor whiteColor]];
    
    shopAmount = [[UILabel alloc] init];
    shopAmount.text = @"5";
    shopAmount.textColor = [UIColor colorWithRed:0.999  green:0.229  blue:0.232 alpha:1];
    shopAmount.font = [UIFont systemFontOfSize:40];
    
    shop = [[UILabel alloc] init];
    shop.textColor = [UIColor colorWithRed:0.525  green:0.526  blue:0.525 alpha:1];
    shop.font = [UIFont systemFontOfSize:16];
    shop.text = @"个商家给出报价";
    
    logoImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LOGO"]];
    
    
    self.circle = [[BCCircleView alloc] initWithLineColor:[UIColor colorWithRed:1  green:0.610  blue:0 alpha:1]];
    self.circle.percent = 100;
    self.circle.backgroundColor = [UIColor clearColor];
    [self.view addSubview:sliderBack];
    [self.view addSubview:self.circle];
    [self.view addSubview:sliderImg];
    [self.view addSubview:shopAmount];
    [self.view addSubview:shop];
    [self.view addSubview:logoImg];
    [sliderImg addSubview:timeLab];
    [sliderImg addSubview:timeTitle];

    [self.view addSubview:goCheckBut];
    [sliderBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH - 170);
        make.height.mas_equalTo(SCREEN_WIDTH - 170);
        make.top.mas_equalTo(80);
    }];
    
    [goCheckBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.bottom.and.right.mas_equalTo(-12);
        make.height.mas_equalTo(50);
        
    }];
    
    
    [self.circle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH - 150);
        make.height.mas_equalTo(SCREEN_WIDTH - 150);
        make.top.mas_equalTo(70);

        
    }];
    
    [sliderImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH - 150);
        make.height.mas_equalTo(SCREEN_WIDTH - 150);
        make.top.mas_equalTo(70);

    }];
    
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    [timeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(timeLab.mas_bottom);
        make.height.mas_equalTo(20);
        
    }];
    
    [shop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(sliderBack.mas_bottom).with.offset(40 *hx);
        make.height.mas_equalTo(20);
        make.centerX.mas_equalTo(10);
        
    }];
    [shopAmount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(shop);
        make.height.mas_equalTo(40);
        make.right.mas_equalTo(shop.mas_left);
        
    }];
    
    [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(goCheckBut.mas_top).with.offset(-20);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(160);
        
    }];
    
    [goCheckBut addTarget:self action:@selector(goPush) forControlEvents:UIControlEventTouchUpInside];
    sliderBack.layer.cornerRadius = (SCREEN_WIDTH - 170)/2;
    time = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(getTimeLink) userInfo:nil repeats:YES];
}

- (void)goPush{
    [time invalidate];
    BCPaidListingViewController *paidListVC = [[BCPaidListingViewController alloc] init];
    [self.navigationController pushViewController:paidListVC animated:YES];

}

- (void)getTimeLink{
    if (self.circle.percent > 1) {
        self.circle.percent -=(100.0 /180);
        second -= 1;
        timeLab.text = [NSString stringWithFormat:@"%ld s", second];
    }else{
        [self goPush];
        second = 180;
        self.circle.percent = 100;
    }
    
}


@end
